package com.isyscore.mapper.admin;

import com.isyscore.dto.sys.ListDeptForm;
import com.isyscore.entity.admin.SysDept;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.isyscore.entity.admin.SysUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 部门表 Mapper 接口
 * </p>
 *
 * @author LGL
 * @since 2024年10月25日
 */
@Mapper
public interface SysDeptMapper extends BaseMapper<SysDept> {

    /**
     * 查询部门列表
     * @param form
     * @return
     */
    List<SysDept> getDeptList(ListDeptForm form);

    /**
     * 根据部门ID查询用户
     * @param deptId
     * @return
     */
    @Select("SELECT count(su.user_id) FROM sys_dept AS dept " +
            "LEFT JOIN sys_role_dept AS role_dept ON dept.dept_id = role_dept.dept_id " +
            "LEFT JOIN sys_user_role AS user_role ON role_dept.role_id = user_role.role_id " +
            "LEFT JOIN sys_user su ON user_role.user_id = su.user_id " +
            "WHERE dept.dept_id = #{deptId}")
        Integer selectUserListByDeptId(Long deptId);

}
